﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NGinnBPM.Runtime;
using NGinnBPM.Lib.Interfaces;
namespace NGinnBPM.Services
{
    /// <summary>
    /// Repository of task instances. Provides task state persistence.
    /// </summary>
    public interface ITaskInstanceRepository
    {
        TaskInstance GetTaskInstance(string correlationId);
        void UpdateTaskInstance(TaskInstance inst);
        void InsertTaskInstance(TaskInstance inst);
        /// <summary>
        /// Return list of ids of tasks that are ready to be processed
        /// (can be kicked).
        /// </summary>
        /// <param name="maxNum"></param>
        /// <returns></returns>
        IList<string> GetTaskInstancesReadyForProcessing(int maxNum);

        /// <summary>
        /// Update scheduling status.
        /// Optional.
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="status"></param>
        /// <param name="additionalInfo"></param>
        void UpdateTaskSchedulingStatus(string instanceId, TaskSchedulingStatus status, string additionalInfo);
        /// <summary>
        /// Update all active instances of a task - set its scheduling status to Ready
        /// if the task was paused. Used when removing a barrier.
        /// </summary>
        /// <param name="processDefinition"></param>
        /// <param name="taskId"></param>
        void SetWaitingTaskInstancesReady(string processDefinition, string taskId);

        /// <summary>
        /// Search for processes with specified correlation Id
        /// and definition ID
        /// </summary>
        /// <param name="processCorrelationId"></param>
        /// <returns></returns>
        IList<string> FindProcessesByCorrelationId(string processCorrelationId, string definitionId);
    }
}
